package com.bwie.goods.service.impl;

import com.bwie.common.domain.Shopping;
import com.bwie.common.domain.request.ShoppingRequest;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.goods.mapper.ShoppingMapper;
import com.bwie.goods.service.ShoppingService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppingServiceimpl implements ShoppingService {
    @Autowired
    private ShoppingMapper shoppingMapper;

    @Override
    public Result<PageResult<Shopping>> list(ShoppingRequest shoppingRequest) {
        PageHelper.startPage(shoppingRequest.getPageNum(),shoppingRequest.getPageSize());

        List<Shopping> list = shoppingMapper.list(shoppingRequest);

        PageInfo<Shopping> shoppingPageInfo = new PageInfo<>(list);

        return PageResult.toResult(shoppingPageInfo.getTotal(),list);
    }

    @Override
    public Result<List<Shopping>> findById() {
        List<Shopping> list = shoppingMapper.findById();
        return Result.success(list);
    }
}
